package org.or5e.oss.core.api.sms;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.or5e.oss.core.BaseObject;

public class SMS_API_Service extends BaseObject {
	private String _smsAPI = "";
	private SMSService _smsService = null;
	private static SMS_API_Service _service = null;
	private static  Map<String, SMS_API_Service> _serviceList = new HashMap<String, SMS_API_Service>();
	
	private SMS_API_Service() {
		this("org.or5e.oss.core.api.sms.SMS_API_Service.SMSServiceImpl");
	}

	private SMS_API_Service(String _smsApi) {
		this._smsAPI = _smsApi;
		try {
			_smsService = (SMSService)Class.forName(this._smsAPI).newInstance();
		} 
		catch (InstantiationException e) {
			e.printStackTrace();
		}
		catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	public static SMSService getSMSService(String _smsSpi) {
		if(_serviceList.containsKey(_smsSpi)) {
			return _serviceList.get(_smsSpi).get_smsService();
		}
		else {
			SMS_API_Service _newService = new SMS_API_Service();
			_serviceList.put(_smsSpi, _newService);
			return _newService.get_smsService();
		}
	}
	
	public static SMSService getSMSService() {
		if(_service == null) {
			_service = new SMS_API_Service();
		}
		return _service.get_smsService();
	}
	@Override
	public String getName() {
		return "SMS_API_Service";
	}
	
	private static class SMSServiceImpl implements SMSService {

		public boolean close(Double _campaignid) throws SMSException {
			return false;
		}

		public boolean deleteSMS(String msgID, String number, Double _campaignid)
				throws SMSException {
			return false;
		}

		public List<SMSMessage> getSMSMessages(String number, Double _campaignid)
				throws SMSException {
			return null;
		}

		public Double init() throws SMSException {
			return null;
		}

		public boolean sendSMS(String _from, String _to, String _message,
				Double _campaignid) throws SMSException {
			return false;
		}

		public boolean sendSMS(String _from, List<String> _to, String _message,
				Double _campaignid) throws SMSException {
			return false;
		}
		
	}

	public final String get_smsAPI() {
		return _smsAPI;
	}

	public final SMSService get_smsService() {
		return _smsService;
	}
}